#! /bin/bash
# Program:
# Start the heng master
base="`dirname $(which "$0")`/.."
ROOTDIR=`(cd "$base"; echo $PWD)`

export HENG_ROOT=$ROOTDIR
export HENG_EBIN=$ROOTDIR/ebin
export HENG_CONF_PATH=$ROOTDIR/conf

[ "x" = "x"$MASTERNAME ] && MASTERNAME=heng_master
[ "x" = "x"$MASTERIP ] && MASTERIP="127.0.0.1"
[ "x" = "x"$MASTERPORT ] && MASTERPORT="6161"
[ "x" = "x"$RSH ] && RSH=ssh

ERL_FLAGS="+K true +A 64 +W w -connet_all false -smp auto -rsh ${RSH}"

#echo $HENG_CONF_PATH
#echo $ERL_FLAGS

erl \
    ${ERL_FLAGS} \
    -pa ${HENG_EBIN} ${HENG_CONF_PATH} \
    -config ${HENG_EBIN}/heng \
    -sname ${MASTERNAME} \
    -eval 'io:format("hello")' \
    "$@"
